/*
Swiper effect
*/
var $featured_slides;
var $jfamily_magazine;
var $blogger_block;

(function ($, Drupal, window, document, undefined) {

    $(document).ready(function() {
  
  //	var page_width 	= $(window).width();
  //	var page_height = $(window).height();
  //	var is_mobile 	= (page_width < 480 && page_width < page_height) || (page_width < 640 && page_width > page_height); 
  	
  	
  	$featured_slides = $(".swiper.featured-slides .swiper-container").swiper({
        watchActiveIndex: true,
        slidesPerView: 1,
        visibilityFullFit: true,
        calculateHeight: true,
        //        centeredSlides: true,
        autoplay: 6000,
        resizeReInit: true,
        onSwiperCreated: function(swiper) {
  
              // Add Next & Prev button
              
            if ($('.swiper.featured-slides .views-row-first .views-field-body').length < 1) {
                $('.swiper.featured-slides .views-field-body .swiper-control, .swiper.featured-slides .views-field-body .swiper-button').addClass("element-invisible");
                $('.swiper.featured-slides .view-footer .swiper-control, .swiper.featured-slides .view-footer .swiper-button').removeClass('mobile');
            }
              var $swiper = $('.swiper.featured-slides');
              if ($swiper.find(".swiper-slide").length > 1) {
                  $swiper.find(".slide-button.next").click(function() {
                      swiper.swipeNext();
                  });
                  $swiper.find(".slide-button.prev").click(function() {
                      swiper.swipePrev();
                  });
              }else{
  //                 $swiper.find(".swiper-control").remove();
              }
          }
  	});
      
  	$blogger_block = $(".swiper.blogger-block .swiper-container").swiper({
        watchActiveIndex: true,
        slidesPerView: 4,
        visibilityFullFit: true,
        calculateHeight: true,
//        centeredSlides: true,
//        autoplay: 6000,
        slidesPerGroup: 4,
        pagination: '.swiper-pagination',
        paginationAsRange: true,
        paginationClickable: true,
        resizeReInit: true,
        onInit: function(swiper) {
            
            $(".swiper-pagination-switch").each(function() {
                var index = ($(this).index() + 4)%4;
                if (index != 0) {
                    $(this).attr("hidden", "");
                }
            })
        }
    });
      
  	$jfamily_magazine = $(".swiper.jfamily-magazine .swiper-container").swiper({
          watchActiveIndex: true,
          slidesPerView: 5,
          visibilityFullFit: true,
          calculateHeight: true,
  //        centeredSlides: true,
          autoplay: 6000,
          resizeReInit: true,
          onSwiperCreated: function(swiper) {
  
              // Add Next & Prev button
              
              var $swiper = $('.swiper.jfamily-magazine');
              if ($swiper.find(".swiper-slide").length > 1) {
                  $swiper.find(".slide-button.next").click(function() {
                      swiper.swipeNext();
                  });
                  $swiper.find(".slide-button.prev").click(function() {
                      swiper.swipePrev();
                  });
              }else{
  //                 $swiper.find(".swiper-control").remove();
              }
          }
    });
      
  	$(".swiper.field-type-image").each(function() {
        var $this = $(this);
        var $container = $(this).find(".swiper-container");
        
            $container.swiper({
              watchActiveIndex: true,
              slidesPerView: 3,
              visibilityFullFit: true,
              calculateHeight: true,
      //        centeredSlides: true,
    //          autoplay: 6000,
              resizeReInit: true,
              onSwiperCreated: function(swiper) {

                  // Add Next & Prev button
                  

                  if ($this.find(".swiper-slide").length >= 3) {
                      $this.find(".slide-button.next").click(function() {
                          swiper.swipeNext();
                      });
                      $this.find(".slide-button.prev").click(function() {
                          swiper.swipePrev();
                      });
                  }else{
                       $this.find(".swiper-control").remove();
                  }
              }
        });
    })
  	
  	
      // if ($(".swiper.meet-our-team .views-row").length < 6) {
          
      //     meet_our_team = $(".swiper.meet-our-team .swiper-container").swiper({
      //         watchActiveIndex: true,
      //         slidesPerView: "auto",
      //         visibilityFullFit: true,
      //         calculateHeight: true,
      // //        centeredSlides: true,
      //         resizeReInit: true,
      // //        loop: true,
      // //        loopAdditionalSlides: 5,
      // //        loopedSlides: 3,
      //         onSwiperCreated: function(swiper) {
  
      //         }
      //     });
      // } else {
          
      //     meet_our_team = $(".swiper.meet-our-team .swiper-container").swiper({
      //         watchActiveIndex: true,
      //         slidesPerView: 'auto',
      //         visibilityFullFit: true,
      //         calculateHeight: true,
      //         centeredSlides: true,
      //         resizeReInit: true,
      //         loop: true,
      // //        loopAdditionalSlides: 5,
      //         loopedSlides: 5,
      //         onSwiperCreated: function(swiper) {
  
      //         }
      //     });
      // }
  	
  	
  });
})(jQuery, Drupal, this, this.document);